layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var businessProcessTable = null;
    var view ={
        init:function(businessId, businessType){
            this.initTable(businessId, businessType);
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),businessProcessTable)
            }
        },
        initTable:function(businessId, businessType){
            var param = "businessId="+businessId;
            if(businessType !== undefined && businessType != null && businessType != ''){
                param+="&businessType="+businessType;
            }
            businessProcessTable = table.render({
                elem : '#businessProcessTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/businessProcess/list.json?'+param// 数据接口
                ,page : Lib.tablePage // 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },

                    {

                        field : 'businessState',
                        title : '业务状态',
                        align: 'center',
                        width:"135"
                    },

                    {

                        field : 'processTime',
                        title : '处理时间',
                        width:"180"
                    },
                    {

                        field : 'processUserName',
                        title : '处理人',
                        width:"135"
                    },
                    {

                        field : 'handlingSuggestion',
                        title : '处理意见',
                        width:"330"
                    },
                    {

                        field : 'processResult',
                        title : '审核结果',
                        width:"135"
                    }

                ] ]

            });

            table.on('checkbox(businessProcessTable)', function(obj){
                var businessProcess = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },

        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),businessProcessTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    var url = "/cms/businessProcess/add.do";
                    Common.openDlg(url,"BusinessProcess管理>新增");
                },
                edit : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"businessProcessTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/businessProcess/edit.do?id="+data.id;
                    Common.openDlg(url,"BusinessProcess管理>编辑");
                },
                del : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del;
                        delView.delBatch();
                    });
                }
            };
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('index',view);

});